home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-02-03 | 6.3 KB | 237 lines | [TEXT/PJMM] |
- {****************************************************}
- {}
- { CShLevelsTable.p }
- {}
- { Array pane class for displaying the list of levels held by the game director. }
- {}
- {****************************************************}
-
-
- unit CShLevelsTable;
-
- interface
-
- uses
- TCL, ShIntf;
-
- implementation
-
- const
- kNumh = 0;
- kNameh = 35;
- kPlayerh = 190;
- kMovesh = 320;
- kTimeh = 380;
-
-
- {****************************************************}
- {}
- { CShLevelsTable }
- {}
- { Construction of the levels table object. }
- {}
- {****************************************************}
-
- procedure CShLevelsTable.IShLevelsTable (anEnclosure: CView;
- aSupervisor: CShGameDirector;
- aWidth, aHeight, aHEncl, aVEncl: Integer;
- aHSizing, aVSizing: SizingOption);
-
- begin { IShLevelsTable }
- itsGameDirector := aSupervisor;
-
- IArrayPane(anEnclosure, aSupervisor, aWidth, aHeight, aHEncl, aVEncl, aHSizing, aVSizing);
-
- FitToEnclosure(kDoHorizontal, kDoVertical);
- SetSelectionFlags(selOnlyOne);
- SetDblClickCmd(cmdClickStart);
- end; { IShLevelsTable }
-
-
- {****************************************************}
- {}
- { Free }
- {}
- { Destruction of the levels table object. We set our pointers to nil, for the }
- { objects to which they were pointing will be disposed of in inherited methods. }
- {}
- {****************************************************}
-
- procedure CShLevelsTable.Free;
-
- begin { Free }
- itsGameDirector := nil;
-
- inherited Free;
- end; { Free }
-
-
- {****************************************************}
- {}
- { DoCommand }
- {}
- { The levels table is responsible for clearing the players from its array, }
- { and then bouncing the command to the game director. }
- {}
- {****************************************************}
-
- procedure CShLevelsTable.DoCommand (theCommand: longint);
-
- procedure Level_SetDefaultBestPlayer (aLevel: CShLevel);
-
- begin { Level_SetDefaultBestPlayer }
- aLevel.SetDefaultBestPlayer;
- end; { Level_SetDefaultBestPlayer }
-
- begin { DoCommand }
- if theCommand = cmdClearBestPlayers then begin
- CCluster(GetArray).DoForEach(Level_SetDefaultBestPlayer);
- Refresh;
- end; { if }
- inherited DoCommand(theCommand); { Pass on to application to do its part. }
- end; { DoCommand }
-
-
- {****************************************************}
- {}
- { UpdateMenus }
- {}
- { The levels table is responsible for enabling the clear best players command. }
- {}
- {****************************************************}
-
- procedure CShLevelsTable.UpdateMenus;
-
- begin { UpdateMenus }
- inherited UpdateMenus;
-
- if not itsGameDirector.IsPlaying then begin
- gBartender.EnableCmd(cmdClearBestPlayers);
- end; { if }
- end; { UpdateMenus }
-
-
- {****************************************************}
- {}
- { DoKeyDown }
- {}
- { Do the double click command if return/enter is pressed. }
- {}
- {****************************************************}
-
- procedure CShLevelsTable.DoKeyDown (theChar: Char;
- keyCode: Byte;
- macEvent: EventRecord);
-
- begin { DoKeyDown }
- { If we are playing a game, then the levels table ignores all keystrokes. }
- { That is, effectively it doesn't exist. }
- if not itsGameDirector.IsPlaying then begin
- if (theChar = kReturnKey) | (theChar = kEnterKey) then begin
- { The double click command is to simulate a click on the start button. }
-
- DoCommand(dblClickCmd);
- end { if }
- else begin
- inherited DoKeyDown(theChar, keyCode, macEvent);
- end; { else }
- end { if }
- else begin
- { Pass onto supervisor. }
- itsGameDirector.DoKeyDown(theChar, keyCode, macEvent);
- end; { else }
- end; { DoKeyDown }
-
-
- {****************************************************}
- {}
- { DrawCell }
- {}
- { Draw the level number, name and best player statistics. }
- {}
- {****************************************************}
-
- procedure CShLevelsTable.DrawCell (theCell: Cell;
- cellRect: Rect);
-
- var
- theNumStr: Str255;
- theLevel: CShLevel;
-
- function TimeText (aDuration: LongInt): Str255;
-
- var
- hoursStr, minutesStr, secondsStr: Str255;
-
- begin { TimeText }
- aDuration := aDuration div 60;
- NumToString(aDuration mod 60, secondsStr);
- if Length(secondsStr) < 2 then begin
- secondsStr := Concat('0', secondsStr);
- end; { if }
-
- aDuration := aDuration div 60;
- NumToString(aDuration mod 60, minutesStr);
- if Length(minutesStr) < 2 then begin
- minutesStr := Concat('0', minutesStr);
- end; { if }
-
- aDuration := aDuration div 60;
- NumToString(aDuration, hoursStr);
-
- TimeText := Concat(hoursStr, ':', minutesStr, ':', secondsStr);
- end; { TimeText }
-
- begin { DrawCell }
- { The list of levels is owned by the array pane. Because }
- { it is an array, we have to cast it, but it is a safe cast. }
-
- theLevel := CShLevel(CList(GetArray).NthItem(theCell.v + 1));
- if theLevel <> nil then begin
-
- NumToString(theCell.v + 1, theNumStr);
- MoveTo(cellRect.left + indent.h + kNumh, cellRect.top + indent.v);
- DrawString(theNumStr);
-
- MoveTo(cellRect.left + indent.h + kNameh, cellRect.top + indent.v);
- DrawString(theLevel.GetName);
-
- MoveTo(cellRect.left + indent.h + kPlayerh, cellRect.top + indent.v);
- DrawString(theLevel.GetPlayer);
-
- MoveTo(cellRect.left + indent.h + kMovesh, cellRect.top + indent.v);
- NumToString(theLevel.GetMoves, theNumStr);
- DrawString(theNumStr);
-
- MoveTo(cellRect.left + indent.h + kTimeh, cellRect.top + indent.v);
- DrawString(TimeText(theLevel.GetTime));
- end; { if }
- end; { DrawCell }
-
-
-
- {****************************************************}
- {}
- { RowSelected }
- {}
- { Returns the index of the row in the table which is selected, 0 if none. }
- {}
- {****************************************************}
-
- function CShLevelsTable.RowSelected: LevelsRange;
-
- var
- theCell: Cell;
-
- begin { RowSelected }
- SetCell(theCell, 0, 0);
- if GetSelect(TRUE, theCell) then begin
- RowSelected := LevelsRange(theCell.v + 1);
- end
- else begin
- RowSelected := kNoLevel;
- end; { if }
- end; { RowSelected }
-
-
- end. { CShLevelsTable }